package org.raphaello.davinci;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.TextView;
import android.widget.Toast;

public class DavinciActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        Gallery g = (Gallery)findViewById(R.id.widget_list);
        g.setAdapter(new WidgetsAdapter(this));
        g.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {

				Toast.makeText(DavinciActivity.this, "item " + position + " is selected.", Toast.LENGTH_SHORT).show();
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// Do nothing
			}
        	
        });
        
        Shape s = (Shape)findViewById(R.id.test_shape);
        s.setOnClickListener(new View.OnClickListener(){

			@Override
			public void onClick(View v) {
				if(v.getAnimation() == null){
					findViewById(R.id.test_shape).startAnimation(AnimationUtils.loadAnimation(DavinciActivity.this, R.anim.alpha));
				}
				else{
					v.clearAnimation();
				}
			}
        	
        	
        });
        //s.startAnimation(AnimationUtils.loadAnimation(this, R.anim.alpha));
        
    }
    
    class WidgetsAdapter extends BaseAdapter {

    	private Context mContext;
    	
    	private String[] mWidgets = {"ImageView", "TextView", "ScrollView", "GalleryView", "RatingBar"};
    	
    	public WidgetsAdapter(Context context) {
    		mContext = context;
    	}
    	
		@Override
		public int getCount() {
			return mWidgets.length;
		}

		@Override
		public Object getItem(int position) {
			return mWidgets[position];
		}

		@Override
		public long getItemId(int position) {
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			TextView t = new TextView(mContext);
			
			t.setText(mWidgets[position]);
			t.setLayoutParams(new Gallery.LayoutParams(100, 60));
			t.setTextColor(0xFFFFFFFF);
			
			
			
			return t;
		}
    	
    }
}